package com.dycloud.project.config;


import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author : renhang
 * @description WxService
 * @date : 2025-07-07 14:33
 **/
@Configuration
@EnableConfigurationProperties(WxConfig.class)
public class WxService {

    @Bean
    public WxMaService wxMaService(WxConfig wxConfig) {
        // 从游戏配置中获取微信小程序的appid和secret
        WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
        config.setAppid(wxConfig.getAppId());
        config.setSecret(wxConfig.getSecret());
        WxMaService service = new WxMaServiceImpl();
        service.setWxMaConfig(config);
        return service;
    }
}
